package com.iwdnb.gkgz.common.utils;

import java.math.BigDecimal;
import java.util.List;

import com.iwdnb.gkgz.common.model.dto.StockDayData;

public class StockVolumeUtils {

    /**
     * 计算股票当天成交量与50日内平均成交量的比率
     *
     * @param stockDayData
     * @param stockDayDataList
     * @return
     */
    public static BigDecimal getScaleOfBeforeDays(StockDayData stockDayData, List<StockDayData> stockDayDataList) {
        if (stockDayDataList.size() > 50) {
            stockDayDataList = stockDayDataList.subList(stockDayDataList.size() - 50, stockDayDataList.size());
        }
        Integer sum = new Integer(0);
        for (StockDayData data : stockDayDataList) {
            sum += data.getTradeNum();
        }
        double averageTradeNum = sum.doubleValue() / stockDayDataList.size();
        return BigDecimalUtils.round(new BigDecimal(stockDayData.getTradeNum() / averageTradeNum));
    }
}
